<!DOCTYPE html>
<title>document.contentType</title>
<link rel="help" href="https://dom.spec.whatwg.org/#dom-document-contenttype">
<script src="/js-test-resources/js-test.js"></script>
<body>

<script>
window.jsTestIsAsync = true;

var toTest = [
    { mt: "text/html", uri: "resources/send-mime-type.php?m=text/html" },
    { mt: "text/xml", uri: "resources/send-mime-type.php?m=text/xml" },
    { mt: "application/xml", uri: "resources/send-mime-type.php?m=application/xml" },
    { mt: "text/html", uri: "resources/send-mime-type.php?m=text/html;charset=utf-8" },
    { mt: "text/xml", uri: "resources/send-mime-type.php?m=text/xml;charset=utf-8" },
    { mt: "application/xml", uri: "resources/send-mime-type.php?m=application/xml;charset=utf-8" }
];

function onrequestload(expectedMimeType) {
    shouldBeEqualToNumber('xhr.status', 200);

    if (xhr.responseXML)
        shouldBeEqualToString('xhr.responseXML.contentType', expectedMimeType);
    else
        testFailed("Null document for mime-type " + expectedMimeType);

    stepTest();
}

var xhr;

function stepTest() {
    var thisTest = toTest.shift();
    if (thisTest) {
        xhr = new XMLHttpRequest();
        xhr.open('GET', thisTest.uri, true);
        xhr.responseType = 'document';
        xhr.onload = onrequestload.bind(null, thisTest.mt);
        xhr.send('');
    } else {
        finishJSTest();
    }
}

stepTest();

</script>
